package com.ruoyi.system.api.interceptor;

import com.ruoyi.common.core.utils.HMACSHA256;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Value;

public class RemoteViewInterceptor implements RequestInterceptor {
    @Value("${file.appid}")
    private String appid;
    @Value("${file.secret}")
    private String secret;
    @Value("${file.time-out}")
    private String timeOut;

    @Override
    public void apply(RequestTemplate requestTemplate) {
        String path = requestTemplate.path();
        String[] split = path.split("/");
        String fileId =split[split.length-1];
        long ts = System.currentTimeMillis() / 1000;
        String sign = HMACSHA256.sign(appid + "," + ts + ',' + fileId + ',' + timeOut, secret);
        requestTemplate.query("appId", appid);
        requestTemplate.query("timestamp", String.valueOf(ts));
        requestTemplate.query("expires",timeOut);
        requestTemplate.query("sign",sign);
    }

}
